package com.bluejie.bluej.java.design.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 代理模式
 */
public class MyProxy1 implements InvocationHandler {
    private Object target;


    public Object getInstance(Object target){
        this.target = target;
        return  Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);

    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("--MyProxy1--invoke()--");
        return method.invoke(target,args);
    }
}
